# This file is part of Sonedyan.
#
# Sonedyan is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public
# License as published by the Free Software Foundation;
# either version 3 of the License, or (at your option) any
# later version.
#
# Sonedyan is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied
# warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
# PURPOSE.  See the GNU General Public License for more
# details.
#
# You should have received a copy of the GNU General Public.
# If not, see <http://www.gnu.org/licenses/>.
#
# Copyright (C) 2009-2012 Jimmy Dubuisson <jimmy.dubuisson@gmail.com>

source("misc.R")

#####
# read original NFA dataset, get its main SCC and save it to a file
#####

#g <- read.graph(file = "nfa-dataset.xml", format = "graphml")

# set nodes 'name' attribute
#V(g)$name <- V(g)$id

#print.graph.all.stats(g, "Original NFA Graph")

# get main WCC
#mainWccVertexIndexes = get.main.cc.vertex.indexes(g, mode = "weak")
#mainWcc <- subgraph(g, mainWccVertexIndexes)

#printAllStats(g, "FA Main WCC")

# get main SCC
#mainSccVertexIndexes = get.main.cc.vertex.indexes(g)
#facore <- subgraph(g, mainSccVertexIndexes)

#write.graph(facore, file= "fa-core-graphml.xml", format = "graphml")
#write.graph(facore, file= "fa-core-gml.gml", format = "gml")

#####
# load FA & DD cores
#####

# load FA-Core 
#facore <- read.graph(file = "fa-core-graphml.xml", format = "graphml")
#print.graph.global.stats(facore, "FA-Core")
#print.graph.all.stats(facore, "FA-Core")
#plot(degree.distribution(facore), xlab = "degree", ylab = "frequency", pch = 1, col = 1, xlim = c(0, 40), ylim = c(0, 0.2), type = "b")

# load DD-Core 
#ddcore <- read.graph(file = "dd-core-graphml.xml", format = "graphml")
#print.graph.global.stats(ddcore, "DD-Core")
#print.graph.all.stats(ddcore, "DD-Core")
#points(degree.distribution(ddcore), pch = 2, col = 2, type = "b")

#####
# generate ER random graphs
#####

# generate ER random graph comparable to the FA core
# method 1: Gnm random graph
#faer <- erdos.renyi.game(4843, 61544, type = "gnm", directed = TRUE)
# method 2: Gnp random graph
#faer <- erdos.renyi.game(4843, 0.00262449932421616, type = "gnp", directed = TRUE)
#print.graph.all.stats(faer, "FA-ER")

# generate ER random graph comparable to the FA core
#dder <- erdos.renyi.game(1496, 4766, type = "gnm", directed = TRUE)
# method 2: Gnp random graph
#dder <- erdos.renyi.game(1496, 0.00213098921538819, type = "gnp", directed = TRUE)
#print.graph.all.stats(dder, "DD-ER")

#steps <- 10
#cl <- 2

#
# graph data for FA Core
#
# # vertices
#nv <- 4843
# # edges
#ne <- 61544
# density
#d <- 0.00262449932421616

#
# graph data for DD Core
#
# # vertices
#nv <- 1496
# # edges
#ne <- 4766
# density
#d <- 0.00213098921538819

#metrics <- get.er.metrics(nv, ne, steps, cl)
#print.er.metrics(metrics)

####
# compute graph efficiency
#####

#print(paste("FA Core min cut:", graph.mincut(facore, value.only = TRUE)))
#print(paste("DD Core min cut:", graph.mincut(ddcore, value.only = TRUE)))

#####
# get edges and vertices multiplicities
#####

###
# set graph to be used
#g <- read.graph(file = "fa-core-graphml.xml", format = "graphml")
#g <- read.graph(file = "dd-core-graphml.xml", format = "graphml")

#vnames <- V(g)$id
#enames <- E(g)$id

#g <- erdos.renyi.game(4843, 61544, type = "gnm", directed = TRUE)
#saveRDS(g, "fa-er-graph.rds")

g <- readRDS("fa-er-graph.rds")

V(g)$id <- paste(c(1:length(V(g))), sep = "")
E(g)$id <- paste(c(1:length(E(g))), sep = "")
###

vnames <- V(g)$id
enames <- E(g)$id

nvtot <- length(V(g))
netot <- length(E(g))

# set of cycle lengths
lv <- c(2,3,4,5,6)

###
#vmult <- get.multiplicities(g, lv)

#saveRDS(vmult, "fa-er-multiplicities.rds")

#VH <- vmult$vh
#vmax <- vmult$vmx

#EH <- vmult$eh
#emax <- vmult$emx
###

###
#saveRDS(VH, "fa-er-VH-vertex-multiplicities.rds")
#saveRDS(vmax, "fa-er-vmax-vertex-multiplicities.rds")
#saveRDS(EH, "fa-er-EH-vertex-multiplicities.rds")
#saveRDS(emax, "fa-er-emax-vertex-multiplicities.rds")
###

###
VH <- readRDS("fa-er-VH-vertex-multiplicities.rds")
vmax <- readRDS("fa-er-vmax-vertex-multiplicities.rds")
EH <- readRDS("fa-er-EH-vertex-multiplicities.rds")
emax <- readRDS("fa-er-emax-vertex-multiplicities.rds")
###

print("Computing vertex/edge scores...")

###
#vscores <- get.scores(VH, vmax, lv)
#escores <- get.scores(EH, emax, lv)

#saveRDS(vscores, "fa-er-vscores.rds")
#saveRDS(escores, "fa-er-escores.rds")
###

###
vscores <- readRDS("fa-er-vscores.rds")
escores <- readRDS("fa-er-escores.rds")
###

###
#for (k in names(sort(vscores)))
#	print(paste(k, ": ", vscores[[k]], sep = ""))	
#for (k in names(sort(escores)))
#	print(paste(k, ": ", escores[[k]], sep = ""))	
###

###
print("List of zero-scored vertices/edges...")

non.zero.vnames <- names(which(vscores != 0))
print(paste("# of non-zero scored vertices:", length(non.zero.vnames)))
print(paste("# of vertices:", length(vnames)))
vzero <- setdiff(vnames, names(which(vscores != 0)))
print(paste("# of zero scored vertices:", length(vzero)))

# for ER graphs
non.zero.enames <- names(which(escores != 0))
print(paste("# of non-zero scored edges:", length(non.zero.enames)))
print(paste("# of edges:", length(enames)))
esplit <- strsplit(non.zero.enames, "\\|")

non.ezero <- c()

for (i in 1:length(esplit))
{
	es <- as.numeric(esplit[[i]][1]) - 1
	ee <- as.numeric(esplit[[i]][2]) - 1
	eid <- E(g)[es %->% ee]$id
	non.ezero <- append(non.ezero, eid)
}

#non.ezero <- unique(non.ezero)
print(paste("# of unique non-zero scored edges:", length(non.ezero)))

ezero <- setdiff(enames, non.ezero)
#ezero <- setdiff(enames, names(which(escores != 0)))
print(paste("# of zero scored edges:", length(ezero)))

print(paste("Zero vertex coverage: ", length(vzero)/length(vnames)))
print(paste("Mean vertex scores value", (mean(vscores) * length(vscores))/(length(vscores)+length(vzero))))
print(paste("Zero edge coverage: ", length(ezero)/length(enames)))
print(paste("Mean edge scores value", (mean(escores) * length(escores))/(length(escores)+length(ezero))))
###

hist(vscores, breaks = c(seq(0, 1, .05)), main = "Vscores Distribution for 2 <= k <= 6")
#hist(escores, breaks = c(seq(0, 1, .05)), main = "Escores Distribution for 2 <= k <= 6")

# write vertex / edge profiles to file
writeProfiles <- function(VH, EH)
{
	vprofiles <- c()
	eprofiles <- c()
	
	for (k in keys(VH))
	{
		v <- VH[[k]]
		s <- paste(names(v), collapse = " ");
		s <- paste("", s, "")
		vprofiles[k] <- s
	}
	
	for (k in keys(EH))
	{
		e <- EH[[k]]
		s <- paste(names(e), collapse = " ");
		s <- paste("", s, "")
		eprofiles[k] <- s
	}
	
	# profile -> regex
	prx <- c()
	prx["2"] <- "^ 2 $"
	prx["2+"] <- " 2 "
	prx["3"] <- "^ 3 $"
	prx["3+"] <- " 3 "
	prx["4"] <- "^ 4 $"
	prx["4+"] <- " 4 "
	prx["5"] <- "^ 5 $"
	prx["5+"] <- " 5 "
	prx["6"] <- "^ 6 $"
	prx["6+"] <- " 6 "
	
	pvhist <- c()
	pehist <- c()
	
	for (n in names(prx))
	{
		vpos <- grep(prx[[n]], vprofiles)
		pvhist[n] <- length(vpos) / nvtot
	}
	
	for (n in names(prx))
	{
		epos <- grep(prx[[n]], eprofiles)
		pehist[n] <- length(epos) / netot
	}
	
	# 2 or 3
	vpos2o3 <- union(grep(" 2 ", vprofiles), grep(" 3 ", vprofiles))
	vpos2o3o4 <- union(grep(" 2 ", vprofiles), union(grep(" 3 ", vprofiles), grep(" 4 ", vprofiles)))
	vpos2o3o4o5 <- union(grep(" 2 ", vprofiles), union(grep(" 3 ", vprofiles), union(grep(" 4 ", vprofiles), grep(" 5 ", vprofiles))))
	vpos2o3o4o5o6 <- union(grep(" 2 ", vprofiles), union(grep(" 3 ", vprofiles), union(grep(" 4 ", vprofiles), union(grep(" 5 ", vprofiles), grep(" 6 ", vprofiles)))))
	# 2 and 3
	vpos2a3 <- intersect(grep(" 2 ", vprofiles), grep(" 3 ", vprofiles))
	vpos2a4 <- intersect(grep(" 2 ", vprofiles), grep(" 4 ", vprofiles))
	vpos2a5 <- intersect(grep(" 2 ", vprofiles), grep(" 5 ", vprofiles))
	vpos2a6 <- intersect(grep(" 2 ", vprofiles), grep(" 6 ", vprofiles))
	vpos3a4 <- intersect(grep(" 3 ", vprofiles), grep(" 4 ", vprofiles))
	vpos3a5 <- intersect(grep(" 3 ", vprofiles), grep(" 5 ", vprofiles))
	vpos3a6 <- intersect(grep(" 3 ", vprofiles), grep(" 6 ", vprofiles))
	vpos4a5 <- intersect(grep(" 4 ", vprofiles), grep(" 5 ", vprofiles))
	vpos4a6 <- intersect(grep(" 4 ", vprofiles), grep(" 6 ", vprofiles))
	vpos5a6 <- intersect(grep(" 5 ", vprofiles), grep(" 6 ", vprofiles))
	vpos2a3a4 <- intersect(grep(" 2 ", vprofiles), intersect(grep(" 3 ", vprofiles), grep(" 4 ", vprofiles)))
	vpos2a3a4a5 <- intersect(grep(" 2 ", vprofiles), intersect(grep(" 3 ", vprofiles), intersect(grep(" 4 ", vprofiles), grep(" 5 ", vprofiles))))
	vpos2a3a4a5a6 <- intersect(grep(" 2 ", vprofiles), intersect(grep(" 3 ", vprofiles), intersect(grep(" 4 ", vprofiles), intersect(grep(" 5 ", vprofiles), grep(" 6 ", vprofiles)))))
	# 2 and !3
	vpos2n3 <- setdiff(grep(" 2 ", vprofiles), grep(" 3 ", vprofiles))
	vpos3n2 <- setdiff(grep(" 3 ", vprofiles), grep(" 2 ", vprofiles))
	vpos2n4 <- setdiff(grep(" 2 ", vprofiles), grep(" 4 ", vprofiles))
	vpos4n2 <- setdiff(grep(" 4 ", vprofiles), grep(" 2 ", vprofiles))
	vpos2n5 <- setdiff(grep(" 2 ", vprofiles), grep(" 5 ", vprofiles))
	vpos5n2 <- setdiff(grep(" 5 ", vprofiles), grep(" 2 ", vprofiles))
	vpos2n6 <- setdiff(grep(" 2 ", vprofiles), grep(" 6 ", vprofiles))
	vpos6n2 <- setdiff(grep(" 6 ", vprofiles), grep(" 2 ", vprofiles))
	vpos3n4 <- setdiff(grep(" 3 ", vprofiles), grep(" 4 ", vprofiles))
	vpos4n3 <- setdiff(grep(" 4 ", vprofiles), grep(" 3 ", vprofiles))
	vpos3n5 <- setdiff(grep(" 3 ", vprofiles), grep(" 5 ", vprofiles))
	vpos5n3 <- setdiff(grep(" 5 ", vprofiles), grep(" 3 ", vprofiles))
	vpos3n6 <- setdiff(grep(" 3 ", vprofiles), grep(" 6 ", vprofiles))
	vpos6n3 <- setdiff(grep(" 6 ", vprofiles), grep(" 3 ", vprofiles))
	vpos4n5 <- setdiff(grep(" 4 ", vprofiles), grep(" 5 ", vprofiles))
	vpos5n4 <- setdiff(grep(" 5 ", vprofiles), grep(" 4 ", vprofiles))
	vpos4n6 <- setdiff(grep(" 4 ", vprofiles), grep(" 6 ", vprofiles))
	vpos6n4 <- setdiff(grep(" 6 ", vprofiles), grep(" 4 ", vprofiles))
	vpos5n6 <- setdiff(grep(" 5 ", vprofiles), grep(" 6 ", vprofiles))
	vpos6n5 <- setdiff(grep(" 6 ", vprofiles), grep(" 5 ", vprofiles))
	
	# 2 or 3
	epos2o3 <- union(grep(" 2 ", eprofiles), grep(" 3 ", eprofiles))
	epos2o3o4 <- union(grep(" 2 ", eprofiles), union(grep(" 3 ", eprofiles), grep(" 4 ", eprofiles)))
	epos2o3o4o5 <- union(grep(" 2 ", eprofiles), union(grep(" 3 ", eprofiles), union(grep(" 4 ", eprofiles), grep(" 5 ", eprofiles))))
	epos2o3o4o5o6 <- union(grep(" 2 ", eprofiles), union(grep(" 3 ", eprofiles), union(grep(" 4 ", eprofiles), union(grep(" 5 ", eprofiles), grep(" 6 ", eprofiles)))))
	# 2 and 3
	epos2a3 <- intersect(grep(" 2 ", eprofiles), grep(" 3 ", eprofiles))
	epos2a4 <- intersect(grep(" 2 ", eprofiles), grep(" 4 ", eprofiles))
	epos2a5 <- intersect(grep(" 2 ", eprofiles), grep(" 5 ", eprofiles))
	epos2a6 <- intersect(grep(" 2 ", eprofiles), grep(" 6 ", eprofiles))
	epos3a4 <- intersect(grep(" 3 ", eprofiles), grep(" 4 ", eprofiles))
	epos3a5 <- intersect(grep(" 3 ", eprofiles), grep(" 5 ", eprofiles))
	epos3a6 <- intersect(grep(" 3 ", eprofiles), grep(" 6 ", eprofiles))
	epos4a5 <- intersect(grep(" 4 ", eprofiles), grep(" 5 ", eprofiles))
	epos4a6 <- intersect(grep(" 4 ", eprofiles), grep(" 6 ", eprofiles))
	epos5a6 <- intersect(grep(" 5 ", eprofiles), grep(" 6 ", eprofiles))
	epos2a3a4 <- intersect(grep(" 2 ", eprofiles), intersect(grep(" 3 ", eprofiles), grep(" 4 ", eprofiles)))
	epos2a3a4a5 <- intersect(grep(" 2 ", eprofiles), intersect(grep(" 3 ", eprofiles), intersect(grep(" 4 ", eprofiles), grep(" 5 ", eprofiles))))
	epos2a3a4a5a6 <- intersect(grep(" 2 ", eprofiles), intersect(grep(" 3 ", eprofiles), intersect(grep(" 4 ", eprofiles), intersect(grep(" 5 ", eprofiles), grep(" 6 ", eprofiles)))))
	# 2 and !3
	epos2n3 <- setdiff(grep(" 2 ", eprofiles), grep(" 3 ", eprofiles))
	epos3n2 <- setdiff(grep(" 3 ", eprofiles), grep(" 2 ", eprofiles))
	epos2n4 <- setdiff(grep(" 2 ", eprofiles), grep(" 4 ", eprofiles))
	epos4n2 <- setdiff(grep(" 4 ", eprofiles), grep(" 2 ", eprofiles))
	epos2n5 <- setdiff(grep(" 2 ", eprofiles), grep(" 5 ", eprofiles))
	epos5n2 <- setdiff(grep(" 5 ", eprofiles), grep(" 2 ", eprofiles))
	epos2n6 <- setdiff(grep(" 2 ", eprofiles), grep(" 6 ", eprofiles))
	epos6n2 <- setdiff(grep(" 6 ", eprofiles), grep(" 2 ", eprofiles))
	epos3n4 <- setdiff(grep(" 3 ", eprofiles), grep(" 4 ", eprofiles))
	epos4n3 <- setdiff(grep(" 4 ", eprofiles), grep(" 3 ", eprofiles))
	epos3n5 <- setdiff(grep(" 3 ", eprofiles), grep(" 5 ", eprofiles))
	epos5n3 <- setdiff(grep(" 5 ", eprofiles), grep(" 3 ", eprofiles))
	epos3n6 <- setdiff(grep(" 3 ", eprofiles), grep(" 6 ", eprofiles))
	epos6n3 <- setdiff(grep(" 6 ", eprofiles), grep(" 3 ", eprofiles))
	epos4n5 <- setdiff(grep(" 4 ", eprofiles), grep(" 5 ", eprofiles))
	epos5n4 <- setdiff(grep(" 5 ", eprofiles), grep(" 4 ", eprofiles))
	epos4n6 <- setdiff(grep(" 4 ", eprofiles), grep(" 6 ", eprofiles))
	epos6n4 <- setdiff(grep(" 6 ", eprofiles), grep(" 4 ", eprofiles))
	epos5n6 <- setdiff(grep(" 5 ", eprofiles), grep(" 6 ", eprofiles))
	epos6n5 <- setdiff(grep(" 6 ", eprofiles), grep(" 5 ", eprofiles))
	
	pvhist["2+3"] <- length(vpos2o3) / nvtot
	pvhist["2+3+4"] <- length(vpos2o3o4) / nvtot
	pvhist["2+3+4+5"] <- length(vpos2o3o4o5) / nvtot
	pvhist["2+3+4+5+6"] <- length(vpos2o3o4o5o6) / nvtot
	pvhist["2&3"] <- length(vpos2a3) / nvtot
	pvhist["2&4"] <- length(vpos2a4) / nvtot
	pvhist["2&5"] <- length(vpos2a5) / nvtot
	pvhist["2&6"] <- length(vpos2a6) / nvtot
	pvhist["3&4"] <- length(vpos3a4) / nvtot
	pvhist["3&5"] <- length(vpos3a5) / nvtot
	pvhist["3&6"] <- length(vpos3a6) / nvtot
	pvhist["4&5"] <- length(vpos4a5) / nvtot
	pvhist["4&6"] <- length(vpos4a6) / nvtot
	pvhist["5&6"] <- length(vpos5a6) / nvtot
	pvhist["2&3&4"] <- length(vpos2a3a4) / nvtot
	pvhist["2&3&4&5"] <- length(vpos2a3a4a5) / nvtot
	pvhist["2&3&4&5&6"] <- length(vpos2a3a4a5a6) / nvtot
	pvhist["2!3"] <- length(vpos2n3) / nvtot
	pvhist["3!2"] <- length(vpos3n2) / nvtot
	pvhist["2!4"] <- length(vpos2n4) / nvtot
	pvhist["4!2"] <- length(vpos4n2) / nvtot
	pvhist["2!5"] <- length(vpos2n5) / nvtot
	pvhist["5!2"] <- length(vpos5n2) / nvtot
	pvhist["2!6"] <- length(vpos2n6) / nvtot
	pvhist["6!2"] <- length(vpos6n2) / nvtot
	pvhist["3!4"] <- length(vpos3n4) / nvtot
	pvhist["4!3"] <- length(vpos4n3) / nvtot
	pvhist["3!5"] <- length(vpos3n5) / nvtot
	pvhist["5!3"] <- length(vpos5n3) / nvtot
	pvhist["3!6"] <- length(vpos3n6) / nvtot
	pvhist["6!3"] <- length(vpos6n3) / nvtot
	pvhist["4!5"] <- length(vpos4n5) / nvtot
	pvhist["5!4"] <- length(vpos5n4) / nvtot
	pvhist["4!6"] <- length(vpos4n6) / nvtot
	pvhist["6!4"] <- length(vpos6n4) / nvtot
	pvhist["5!6"] <- length(vpos5n6) / nvtot
	pvhist["6!5"] <- length(vpos6n5) / nvtot
	
	pehist["2+3"] <- length(epos2o3) / netot
	pehist["2+3+4"] <- length(epos2o3o4) / netot
	pehist["2+3+4+5"] <- length(epos2o3o4o5) / netot
	pehist["2+3+4+5+6"] <- length(epos2o3o4o5o6) / netot
	pehist["2&3"] <- length(epos2a3) / netot
	pehist["2&4"] <- length(epos2a4) / netot
	pehist["2&5"] <- length(epos2a5) / netot
	pehist["2&6"] <- length(epos2a6) / netot
	pehist["3&4"] <- length(epos3a4) / netot
	pehist["3&5"] <- length(epos3a5) / netot
	pehist["3&6"] <- length(epos3a6) / netot
	pehist["4&5"] <- length(epos4a5) / netot
	pehist["4&6"] <- length(epos4a6) / netot
	pehist["5&6"] <- length(epos5a6) / netot
	pehist["2&3&4"] <- length(epos2a3a4) / netot
	pehist["2&3&4&5"] <- length(epos2a3a4a5) / netot
	pehist["2&3&4&5&6"] <- length(epos2a3a4a5a6) / netot
	pehist["2!3"] <- length(epos2n3) / netot
	pehist["3!2"] <- length(epos3n2) / netot
	pehist["2!4"] <- length(epos2n4) / netot
	pehist["4!2"] <- length(epos4n2) / netot
	pehist["2!5"] <- length(epos2n5) / netot
	pehist["5!2"] <- length(epos5n2) / netot
	pehist["2!6"] <- length(epos2n6) / netot
	pehist["6!2"] <- length(epos6n2) / netot
	pehist["3!4"] <- length(epos3n4) / netot
	pehist["4!3"] <- length(epos4n3) / netot
	pehist["3!5"] <- length(epos3n5) / netot
	pehist["5!3"] <- length(epos5n3) / netot
	pehist["3!6"] <- length(epos3n6) / netot
	pehist["6!3"] <- length(epos6n3) / netot
	pehist["4!5"] <- length(epos4n5) / netot
	pehist["5!4"] <- length(epos5n4) / netot
	pehist["4!6"] <- length(epos4n6) / netot
	pehist["6!4"] <- length(epos6n4) / netot
	pehist["5!6"] <- length(epos5n6) / netot
	pehist["6!5"] <- length(epos6n5) / netot
	
	write.csv(pvhist, "fa-er-vprofiles.csv")
	write.csv(pehist, "fa-er-eprofiles.csv")
}

# Documentation

# e <- E(facore)[V(facore)[id == "zoo"] %->% V(facore)[id == "keeper"]]

# Get the distribution without plotting it using tighter breaks
#histogram <- hist(vscores, plot = F, breaks = c(seq(0, length(vscores) + 1, .1)))

# Plot the distribution using log scale on both axes, and use blue points
#plot(histogram$counts, log = "xy", pch = 20, col = "blue", main = "Log-normal distribution", xlab = "Value", ylab = "Frequency")


#####
# get cores cycles
#####

# get DD Core cycles
#get.core.cycles("dd", ddcore, 8)

# get FA Core cycles
#get.core.cycles("fa", facore, 5)

#####
# get cycles reduces graph
#####

#cycles <- get.cycles(facore, 4)
#cnames <- cycles$cn

#rg <- get.cycles.subgraph.reduction(cnames)

#print.graph.global.stats(rg, "FA-Reduced")
#print.graph.all.stats(rg, "FA-Reduced")

#write.graph(rg, file= "reduced-fa-4-cycles-graphml.xml", format = "graphml")
#write.graph(rg, file= "reduced-fa-4-cycles-gml.gml", format = "gml")

###
# analyze reduced graphs
###

#rg <- read.graph(file = "reduced-fa-3cycles-graphml.xml", format = "graphml")
#cg <- read.graph(file = "fa-subgraph-graphml-3-cycles.xml", format = "graphml")
#print.graph.all.stats(rg, "FA-Reduced")
#print.graph.all.stats(cg, "FA-3cycles")

#####
# print cycles length
#####

#cycles <- get.cycles(facore, 5)

#vcm <- cycles$vcm
#ecm <- cycles$ecm

#print(paste("Length vids:", length(cycles$v)))
#print(paste("Length eids:", length(cycles$e)))
#print(paste("Length cycles:", length(cycles$c)))

#print(paste("Length VCM:", length(vcm)))
#print(paste("Max VCM:", max(vcm)))
#print(paste("Min VCM:", min(vcm)))
#print(paste("Avg VCM:", mean(vcm)))
#print("Highest multiplicity vertices:")
#print(sort(vcm, decreasing = TRUE)[1:10])

#print(paste("Length ECM:", length(ecm)))
#print(paste("Max ECM:", max(ecm)))
#print(paste("Min ECM:", min(ecm)))
#print(paste("Avg ECM:", mean(ecm)))
#print("Highest multiplicity edges:")
#print(sort(ecm, decreasing = TRUE)[1:10])

#print("Printing cycle names:")
#print(cycles$cn)

#for (i in c(2:8))
#{
#	cycles <- get.cycles(facore, i)
#	print(length(cycles))
#}

#####
# get colinks graph
#####

# get cores colinks graphs
#facg <- get.colink.graph(facore)
#print.graph.all.stats(facg, "FA-Core colinks")

#ddcg <- get.colink.graph(ddcore)
#print.graph.all.stats(ddcg, "DD-Core colinks")

#facgSccVertexIndexes = get.main.cc.vertex.indexes(facg)
#facgcore <- subgraph(facg, facgSccVertexIndexes)
#print.graph.global.stats(facgcore, "FA-Core colinks core")

#write.graph(facgcore, file= "fa-colinks-core-graphml.xml", format = "graphml")
#write.graph(facgcore, file= "fa-colinks-core-gml.gml", format = "gml")

#####
# get cores intersection
#####

# get intersection of V(DD-Core)$id & V(FA-Core)$id
#interids <- intersect(V(facore)$id, V(ddcore)$id)

# get DD Supercore
#ddsupercore <- get.subgraph(ddcore, interids)
#print.graph.global.stats(ddsupercore, "DD Supercore")

# get FA Supercore
#fasupercore <- get.subgraph(facore, interids)
#print.graph.global.stats(fasupercore, "FA Supercore")

# get DD Supercore cycles
#get.core.cycles("dd-super", ddsupercorei, 5)

# get FA Core cycles
#get.core.cycles("fa-super", fasupercore, 5)


